interface CheckCondition {
    format?: string[],
    size?: number
}

type ErrorType = 'size' | 'format' | null

export function beforUploadCheck(file: File, condition: CheckCondition) {
    const {format, size} = condition
    const isVaildFormat = format ? format.includes(file.type) : true
    const isVaildSize = size ? (file.size / 1024 / 1024 < size) : true
    let error: ErrorType = null
    if (!isVaildFormat) {
        error = 'format'
    }
    if (!isVaildSize) {
        error = 'size'
    }
    return {
        passed: isVaildFormat && isVaildSize,
        error
    }
}
